package cn.stylefeng.guns.modular.working.controller;

import cn.stylefeng.guns.base.auth.annotion.Permission;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.working.entity.Working;
import cn.stylefeng.guns.modular.working.model.params.WorkingParam;
import cn.stylefeng.guns.modular.working.service.WorkingService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;


/**
 * 控制器
 *
 * @author syt
 * @Date 2020-10-11 15:27:15
 */
@Controller
@RequestMapping("/working")
public class WorkingController extends BaseController {

    private String PREFIX = "/working";

    @Autowired
    private WorkingService workingService;

    /**
     * 跳转到主页面
     *
     * @author syt
     * @Date 2020-10-11
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/working.html";
    }

    /**
     * 新增页面
     *
     * @author syt
     * @Date 2020-10-11
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/working_add.html";
    }

    /**
     * 编辑页面
     *
     * @author syt
     * @Date 2020-10-11
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/working_edit.html";
    }

    /**
     * 新增接口
     *
     * @author syt
     * @Date 2020-10-11
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(@Valid WorkingParam workingParam) {
        this.workingService.add(workingParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author syt
     * @Date 2020-10-11
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(WorkingParam workingParam) {
        this.workingService.update(workingParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author syt
     * @Date 2020-10-11
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(WorkingParam workingParam) {
        this.workingService.delete(workingParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author syt
     * @Date 2020-10-11
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(WorkingParam workingParam) {
        Working detail = this.workingService.getById(workingParam.getWorkingId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author syt
     * @Date 2020-10-11
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(WorkingParam workingParam) {
        return this.workingService.findPageBySpec(workingParam);
    }

}


